import HttpRequest from "@/utils/axios";
const axios = new HttpRequest();

/**
 * GET 请求
 * @param url 请求URL
 * @param data 请求数据
 * @returns {Promise}
 */
export const _get = (url, data) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: url,
        params: data,
        method: "get",
      })
      .then((res) => {
        if (res.status === "SUCCESS") {
          resolve(res.data);
        } else {
          reject(res);
        }
      })
      .catch((err) => {
        if (err && err.response) {
          reject(err);
        }
      });
  });
};

export const _post = (url, data) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: url,
        data: data,
        method: "post",
      })
      .then((res) => {
        if (res.status === "SUCCESS") {
          resolve(res.data);
        } else {
          reject(res);
        }
      })
      .catch((err) => {
        if (err && err.response) {
          reject(err);
        }
      });
  });
};
